package com.leoman.service.impl;

import com.leoman.core.Constant;
import com.leoman.dao.UserResumeDao;
import com.leoman.entity.UserResume;
import com.leoman.service.UserResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * UserResumeServiceImpl
 * Created by 涂奕恒 on 2016/10/18 0018 下午 3:25.
 */
@Service
public class UserResumeServiceImpl implements UserResumeService {

    @Autowired
    private UserResumeDao userResumeDao;

    @Override
    public List<UserResume> findAll() {
        return userResumeDao.findAll();
    }

    @Override
    public Page<UserResume> find(int pageNum, int pageSize) {
        return userResumeDao.findAll(new PageRequest(pageNum - 1, pageSize, Sort.Direction.DESC, "id"));
    }

    @Override
    public Page<UserResume> find(int pageNum) {
        return find(pageNum, Constant.PAGE_DEF_SIZE);
    }

    @Override
    public UserResume getById(int id) {
        return userResumeDao.findOne(id);
    }

    @Override
    public void deleteById(int id) {
        userResumeDao.delete(id);
    }

    @Override
    public UserResume create(UserResume userResume) {
        return userResumeDao.save(userResume);
    }

    @Override
    public UserResume update(UserResume userResume) {
        return userResumeDao.save(userResume);
    }

    @Override
    @Transactional
    public void deleteAll(int[] ids) {
        for (int id : ids) {
            deleteById(id);
        }
    }
}